let app = getApp();
Page({
  data: {
    flag: -1,
    list: [],
    pages: 0,
    moment: []
  },
  fetchArticleList(pageNo,categoryId) {
    this.loading = true;
    let data = {
      "numPerPage": 99999,
      "order": "asc",
      "pageNum": pageNo,
      "categoryId": categoryId,
      "sort": ""
    }
    // 向后端请求指定页码的数据
    return app.post("productQueryPage", data).then((res) => {
      // 成功后隐藏导航栏加载框
      wx.hideLoading();
      this.loading = false
      this.setData({
        pages: res.data.total,
        moment: res.data.rows
      });
    }).catch((e) => {
      wx.hideLoading();
      app.toast("网络或服务器错误");
    })
  },
  onLoad() {
    wx.showLoading({
      title: '加载中...',
    })
    app.post("category").then((res) => {
      let id = res.data[0].id;
      this.setData({
        list: res.data,
        flag: id
      });
      this.fetchArticleList(1,id);
    }).catch((e) => {
      app.toast("网络或服务器错误");
    });
  },
  activeTap(event) {
    let categoryId = event.currentTarget.id;
    this.setData({flag: categoryId});
    this.fetchArticleList(1, categoryId);
  },
  jumpItem(event) {
    var id = event.currentTarget.id;
    wx.navigateTo({
      url: "/pages/logs/logs?id="+id+""
    });
  },
})